package com.yanqu.road.server.cmd.activity.ghost;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.GhostActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ghost.GhostModule;
import com.yanqu.road.server.manger.activity.ghost.GhostMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.string.StringUtils;

@Cmd(code = GameProtocol.S_GHOST_HANDLE_BOX_EVENT_FROM_CROSS, desc = "处理货箱事件跨服回来")
public class GhostHandleBoxEventFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (!GhostMgr.inOpenTime()) {
            ret = GameErrorCode.E_GHOST_ACTIVITY_NO_OPEN;
            return;
        }
        GhostActivityProto.CrossHandleBoxRespMsg reqMsg = GhostActivityProto.CrossHandleBoxRespMsg.parseFrom(packet.getBytes());
        int boxId = reqMsg.getBoxId();
        ret = player.getModule(GhostModule.class).handleBoxEventFromCross(reqMsg.getRet(),boxId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            GhostActivityProto.HandleBoxEventRespMsg.Builder builder = GhostActivityProto.HandleBoxEventRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_GHOST_HANDLE_BOX_EVENT, builder);
        }
    }
}
